Package edu.uky.ai.csp.kr
Class Solution
java.lang.Object
edu.uky.ai.csp.kr.Solution
- All Implemented Interfaces:
java.lang.Cloneable
public class Solution
extends java.lang.Object
implements java.lang.Cloneable
A solution to a constraint satisfaction problem is an assignment of values to the problem's variables.
A solution is complete when every variable has exactly 1 value in its domain.
A solution can be a partial solution, meaning that we have not yet narrowed down the domains of all variables to a single value.
A solution is impossible if any of its assigned variables (those with 1 value in the domain) violate a constraint in the problem or if any variable has a domain with no values in it (i.e. no legal value).
- Author:
- Stephen G. Ware
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Solutionclone()intcountDescendants()Returns the number of descendant solutions that were generated from this object.DomaingetDomain(Variable variable)Returns the domain (i.e.booleanisComplete()A solution is complete if every variable has a domain of size exactly 1 and none of the problem's constraints are violated.booleanisImpossible()A solution is impossible if any variable has a domain of size 0 (i.e.intsize()The size of a solution is the sum of the sizes of all domains which have more than 1 value.booleantest(Constraint constraint, java.lang.Object left, java.lang.Object right)Given some constraint and two candidate values for the constraint's variables, this method checks if the constraint would be violated by those values.java.lang.StringtoString()
-
Field Details
-
problem
The problem this solution is potentially a solution for
-
-
Constructor Details
-
Solution
Constructs a new solution object for a given problem. The domains of all variables will be set to their domains in the initial state of the problem.- Parameters:
problem- the problem that this object will potentially be a solution for
-
-
Method Details
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
clone
- Overrides:
clonein classjava.lang.Object
-
countDescendants
public int countDescendants()Returns the number of descendant solutions that were generated from this object.- Returns:
- the number of descendants
-
isComplete
public boolean isComplete()A solution is complete if every variable has a domain of size exactly 1 and none of the problem's constraints are violated.- Returns:
- true if this solution is complete, false otherwise
-
isImpossible
public boolean isImpossible()A solution is impossible if any variable has a domain of size 0 (i.e. no legal value) or if any of the problem's constraints have been violated.- Returns:
- true if this solution can never be complete
-
size
public int size()The size of a solution is the sum of the sizes of all domains which have more than 1 value. This implies that size is 0 for a complete solution. The size of a solution is a simple representation of how much work remains to be done before this solution is complete.- Returns:
- the size of the solution
-
getDomain
Returns the domain (i.e. the set of possible values) for a given variable in this solution.- Parameters:
variable- the variable- Returns:
- the variable's domain
-
test
Given some constraint and two candidate values for the constraint's variables, this method checks if the constraint would be violated by those values.- Parameters:
constraint- the constraint to checkleft- the value for the constraint's left variableright- the value for the constraint's right variable- Returns:
- true if the values do not violate the constraint, false otherwise
-